//
//  addressTableViewCell.m
//  lmq
//
//  Created by 千翼网络科技 on 2017/2/3.
//  Copyright © 2017年 yuanxin. All rights reserved.
//

#import "addressTableViewCell.h"
#import "editaddressViewController.h"
#import "configddd.h"
#import <Masonry/Masonry.h>

@implementation addressTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backView=[[UIView alloc]initWithFrame:CGRectMake(0,  0, DEF_SCREEN_WIDTH, screenScale(200))];
        self.backView.backgroundColor=[UIColor whiteColor];
        [self addSubview:self.backView];
        
//        self.status = [[NSString alloc]init];
        
        //标题
        self.titLable=[[UILabel alloc]init];
        self.titLable.text=@"大雄";
        self.titLable.font = get4sFont(14);
        [self.backView addSubview:self.titLable];
        [_titLable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_backView).with.offset(screenScale(26));
            make.left.mas_equalTo(_backView).with.offset(screenScale(20));
            
            make.height.mas_equalTo(screenScale(30));
        }];
        
        self.phoneLable=[[UILabel alloc]init];
        self.phoneLable.text=@"13512341234";
        self.phoneLable.font = get4sFont(12);
        self.phoneLable.textAlignment=NSTextAlignmentRight;
        self.phoneLable.textColor = [UIColor grayColor];
        [self.backView addSubview:self.phoneLable];
        [_phoneLable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_backView).with.offset(screenScale(26));
            make.right.mas_equalTo(_backView).with.offset(screenScale(-20));
            
            make.height.mas_equalTo(screenScale(26));
        }];
        
        self.addressLable=[[UILabel alloc]init];
        self.addressLable.text=@"辽宁省沈阳市大东区大悦城123号123";
        self.addressLable.font = get4sFont(12);
        [self.backView addSubview:self.addressLable];
        [_addressLable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_backView).with.offset(screenScale(70));
            make.left.mas_equalTo(_backView).with.offset(screenScale(20));
            
            make.height.mas_equalTo(screenScale(30));
        }];
        
        //线1
        self.backLineView1=[[UIView alloc]init];
        self.backLineView1.backgroundColor=[ZJCModel colorWithString:@"cccccc"];
        [self.backView addSubview:self.backLineView1];
        [_backLineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_backView).with.offset(screenScale(120));
            make.left.mas_equalTo(_backView).with.offset(0);
            make.width.mas_equalTo(scrWidth());
            make.height.mas_equalTo(screenScale(1));
        }];
        
        //默认地址
        self.selectBtn=[[UIButton alloc]init];
        [self.selectBtn addTarget:self action:@selector(selectBtnClick) forControlEvents:UIControlEventTouchUpInside];
        self.selectBtn.selected = NO;
        [self.backView addSubview:self.selectBtn];
        [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_backLineView1).with.offset(screenScale(20));
            make.left.mas_equalTo(_backView).with.offset(screenScale(20));
            make.width.mas_equalTo(screenScale(150));
            make.height.mas_equalTo(screenScale(30));
        }];
        
        self.selectImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screenScale(28), screenScale(28))];
        self.selectImageView.image=[UIImage imageNamed:@"circile_b"];
        [self.selectBtn addSubview:self.selectImageView];
        
        self.setLable=[[UILabel alloc]initWithFrame:CGRectMake(screenScale(33), 0, screenScale(130), screenScale(30))];
        isSelected=YES;
        self.setLable.text=@"默认地址";
        self.setLable.textColor=[ZJCModel colorWithString:@"cccccc"];
        self.setLable.font = get4sFont(12);
        [self.selectBtn addSubview:self.setLable];
        
        //编辑
        self.editorBtn=[[UIButton alloc]initWithFrame:CGRectMake(screenScale(430), screenScale(120), screenScale(100), screenScale(80))];
        [self.editorBtn addTarget:self action:@selector(editorBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.editorBtn.tag = 1;
        [self.backView addSubview:self.editorBtn];
        
        self.editorImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, screenScale(18), screenScale(32), screenScale(32))];
        self.editorImageView.image=[UIImage imageNamed:@"edit"];
        [self.editorBtn addSubview:self.editorImageView];
        
        self.editorLable=[[UILabel alloc]initWithFrame:CGRectMake(screenScale(37), screenScale(18), screenScale(60), screenScale(35))];
        self.editorLable.text=@"编辑";
        self.editorLable.textColor=[UIColor grayColor];
        self.editorLable.font = get4sFont(12);
        [self.editorBtn addSubview:self.editorLable];
        
        //删除
        self.deleteBtn=[[UIButton alloc]initWithFrame:CGRectMake(screenScale(537), screenScale(120), screenScale(100), screenScale(80))];
        //self.deleteBtn.backgroundColor=[UIColor redColor];
        [self.deleteBtn addTarget:self action:@selector(editorBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.deleteBtn.tag=2;
        [self.backView addSubview:self.deleteBtn];
        
        self.deleteImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, screenScale(18), screenScale(32), screenScale(32))];
        self.deleteImageView.image=[UIImage imageNamed:@"delete"];
        [self.deleteBtn addSubview:self.deleteImageView];
        
        self.deleteLable=[[UILabel alloc]initWithFrame:CGRectMake(screenScale(37), screenScale(18), screenScale(60), screenScale(35))];
        self.deleteLable.text=@"删除";
        self.deleteLable.font = get4sFont(12);
        self.deleteLable.textColor=[UIColor grayColor];
        [self.deleteBtn addSubview:self.deleteLable];
        
        self.backLineView2=[[UIView alloc]initWithFrame:CGRectMake(0, screenScale(190), DEF_SCREEN_WIDTH, screenScale(10))];
        self.backLineView2.backgroundColor=[ZJCModel colorWithString:@"f2f2f2"];
        [self.backView addSubview:self.backLineView2];
    }
    return self;
}

- (void)setDataDic:(NSMutableDictionary *)dataDic{
    
    _dataDic = dataDic;
}

- (void)setStatus:(NSString *)status{
    
    _status = status;
    if ([[NSString stringWithFormat:@"%@",_status]isEqualToString:@"1"]) {
        
        self.selectBtn.selected = YES;
        self.selectImageView.image=[UIImage imageNamed:@"duihao"];
        self.setLable.textColor=[UIColor blackColor];
    }
}

-(void)editorBtnClick:(UIButton *)sender{
    if (sender.tag==1) {
        
        NSLog(@"编辑");
        editaddressViewController *editorVC=[[editaddressViewController alloc]init];
        editorVC.dataDic = _dataDic;
        [((editaddressViewController*)self.addressViewController).navigationController pushViewController:editorVC animated:YES];
        
    }else if (sender.tag==2){
        
        NSLog(@"删除");
        
        NSDictionary *dict =[[NSDictionary alloc]initWithObjectsAndKeys:@"yes",@"delete",_indexPath,@"status", nil];
        NSNotification *notification =[NSNotification notificationWithName:@"status" object:nil userInfo:dict];
        [[NSNotificationCenter defaultCenter] postNotification:notification];
    }
}

-(void)selectBtnClick{
    NSLog(@"默认地址");
    if (self.selectBtn.selected) {
        
//        self.selectBtn.selected = NO;
//        self.selectImageView.image=[UIImage imageNamed:@"circile_b"];
//        self.setLable.textColor=[ZJCModel colorWithString:@"cccccc"];
    }else{
        
//        self.selectBtn.selected = YES;
//        self.selectImageView.image=[UIImage imageNamed:@"duihao"];
//        self.setLable.textColor=[UIColor blackColor];
        
        NSLog(@"-----------%@",_indexPath);
        NSDictionary *dict =[[NSDictionary alloc]initWithObjectsAndKeys:@"yes",@"selected",_indexPath,@"status", nil];
        NSNotification *notification =[NSNotification notificationWithName:@"status" object:nil userInfo:dict];
        [[NSNotificationCenter defaultCenter] postNotification:notification];
    }
}

- (void)setIndexPath:(NSString *)indexPath{
    
    _indexPath = indexPath;
}

@end
